package com.codi.bus.core.dao.impl;

import com.codi.base.dao.PageImpl;
import com.codi.base.dao.plugin.page.PageView;
import com.codi.base.dao.v2.GeneratedBaseDaoImpl;
import com.codi.bus.core.dao.UserMsgDao;
import com.codi.bus.core.domain.FundCombination;
import com.codi.bus.core.domain.UserMsg;
import com.github.pagehelper.PageRowBounds;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2018/4/10.
 */
@Repository("userMsgDao")
public class UserMsgDaoImpl extends GeneratedBaseDaoImpl<UserMsg> implements UserMsgDao {
    @Override
    public int selectByDividend(Long userId, String dividendRecord) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("dividendRecord", dividendRecord);
        return this.getSqlSession().selectOne(this.generateStatement("selectByDividend"), map);
    }

    @Override
    public int selectByAllotNo(Long userId, String allotNo) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("allotNo", allotNo);
        return this.getSqlSession().selectOne(this.generateStatement("selectByAllotNo"), map);
    }

    @Override
    public int selectMessageCount(Long userId, Integer msgType, Long profileId){
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("msgType", msgType);
        map.put("profileId", profileId);
        return this.getSqlSession().selectOne(this.generateStatement("selectMessageCount"), map);
    }

    @Override
    public Page<UserMsg> selectMessage(Long userId, Integer msgType, Integer titleType, Pageable pageable, Long profileId){
        PageRowBounds prb = new PageRowBounds(pageable.getPageNumber(), pageable.getPageSize());

        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("msgType", msgType);
        map.put("titleType", titleType);
        map.put("profileId", profileId);
        List<UserMsg> userMsgs = this.findList(generateStatement("selectMessage"), map, prb);
        return new PageImpl<>(userMsgs, pageable, prb.getTotal());
    }

    @Override
    public int updateMessageState(Long userId, Integer msgType, Long profileId){
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("msgType", msgType);
        map.put("profileId", profileId);
        return this.update(generateStatement("updateMessageState"), map);
    }
}
